
<template>
  <div v-if="visible">
    <el-dialog :visible.sync="visible"
               title="提现设置"
               :modal="false"
               class="user-dialog add-or-updata"
               width="30%"
               :before-close="closeDialog"
               :close-on-click-modal="false"
               :close-on-press-escape="false">
      <el-form :model="dataForm"
               class="label-left-form"
               ref="dataForm"
               label-position="left"
               label-width="124px">
        <el-form-item prop="oneDayQuota"
                      label="单日提现限额">
          <el-input v-model='dataForm.oneDayQuota'
                    placeholder=''></el-input>
        </el-form-item>
        <el-form-item prop="oneDayFrequency"
                      label="单日提现次数">
          <el-input-number v-model="dataForm.oneDayFrequency"
                           controls-position="right"
                           :min="1"
                           class="width-100"
                           :max="100"></el-input-number>
        </el-form-item>
        <el-form-item prop="autoClear"
                      label="是否自动结算提现">
          <el-switch v-model="dataForm.autoClear"
                     :active-value="1"
                     :inactive-value="0"
                     active-color="#13ce66"
                     inactive-color="#ff4949"
                     @change="setStatus($event)">
          </el-switch>
        </el-form-item>
      </el-form>
      <template slot="footer">
        <el-button @click="closeDialog()">{{ $t('cancel') }}</el-button>
        <el-button type="primary"
                   @click="dataFormSubmitHandle()">修改</el-button>
      </template>

    </el-dialog>
  </div>
</template>

<script>
import minFormValidate from '@/mixins/form-validate'
import mixinViewModule from '@/mixins/view-module'
import debounce from 'lodash/debounce'

export default {
  mixins: [mixinViewModule, minFormValidate],
  components: {
  },
  data () {
    return {
      mixinViewModuleOptions: {
        updateURL: '/tb/withdrawDeposit/addWithdrawSet'
      },
      visible: false,
      isRequest: false,
      dialogVisible: false,
      dataForm: {
        autoClear: 0,
        oneDayFrequency: '',
        oneDayQuota: ''
      }
    }
  },
  computed: {
  },
  methods: {
    closeDialog () {
      this.visible = false
    },
    // 修改状态
    setStatus (data) {
      this.dataForm.autoClear = data
    },
    init () {
      this.visible = true
      this.getWithdrawalSet()
    },
    // 获取提现设置
    getWithdrawalSet () {
      this.$http.get('/tb/withdrawDeposit/queryWithdrawSet').then(({ data: res }) => {
        if (res.code !== 0) {
          return
        }
        if (res.data !== '') {
          this.dataForm.oneDayQuota = res.data.oneDayQuota
          this.dataForm.oneDayFrequency = res.data.oneDayFrequency
          this.dataForm.autoClear = res.data.autoClear
        }
      })
    },
    // 表单提交
    dataFormSubmitHandle: debounce(function () {
      this.$refs.dataForm.validate(valid => {
        if (valid) {
          this.isRequest = true
          // const url = this.mixinViewModuleOptions.updateURL
          // this.addOrUpdateItem({ url }).then(res => {
          //   if (res.code !== 0) {
          //     this.isRequest = false
          //     return
          //   }
          //   this.$emit('callBack')
          //   this.closeDialog()
          // })
          this.$http.post('/tb/withdrawDeposit/addWithdrawSet', this.dataForm).then(({ data: res }) => {
            if (res.code !== 0) {
              return this.$message.error(res.msg)
            }
            this.$message.success('操作成功')
            this.$emit('callBack')
            this.closeDialog()
          })
        }
      })
    }, 1000, { 'leading': true, 'trailing': false })
  }
}
</script>

<style lang="scss" scoped>
</style>
